package com.tt.dp.compound.component;

import com.tt.dp.compound.model.Quackable;
import com.tt.dp.compound.observer.Observer;

import java.util.*;

/**
 * 一组
 */
public class Flock implements Quackable {

    private List<Quackable> quackables = new ArrayList<Quackable>();

    public void add(Quackable duck){
        this.quackables.add(duck);
    }

    public void quack() {

        Iterator<Quackable> it = quackables.iterator();

        while(it.hasNext()){
            Quackable duck = it.next();

            duck.quack();
        }
    }

    public void registerObserver(Observer observer) {
        Iterator<Quackable> it = quackables.iterator();

        while (it.hasNext()) {

            Quackable duck = it.next();
            duck.registerObserver(observer);
        }
    }

    public void notifyObservers() {

    }
}
